home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.03 Mar 90 / Mouse Source / TrackSetText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-22  |  1.3 KB  |  52 lines  |  [TEXT/KAHL]

  1. /*                                            TrackSetText.c                                    */
  2. /*
  3.  * Copyright © 1989 Martin Minow. All rights reserved.
  4.  *
  5.  * TrackSetText(text, length, track_handle)
  6.  * text                    Data to insert
  7.  * length                The number of bytes to insert
  8.  * track_handle    The TrackRecord handle
  9.  *
  10.  * Copy the specified text into the TrackRecord.  Any
  11.  * text currently in the TrackRecord is lost.  The
  12.  * selection range is set to an insertion point at the
  13.  * end of the text.  (Note: TextEdit TESetText "doesn't
  14.  * dispose of any text currently in the edit record.")
  15.  * The text origin is reset to "upper-left" corner.
  16.  *
  17.  */
  18. #include    "TrackEdit.h"
  19. #define TR    (*tr)
  20.  
  21. void
  22. TrackSetText(text, length, track_handle)
  23. Ptr                    text;
  24. LONGINT            length;
  25. TrackHandle    track_handle;
  26. {
  27.         register TrackPtr    tr;
  28.         _Track_state            state;
  29.         Boolean                        track_was_active;
  30.         
  31.         /*
  32.          * Dump the selection, stuff the text, then
  33.          * recreate the selection.
  34.          */
  35.         track_was_active =
  36.             _Track_is_set((*track_handle), _Track_is_active);
  37.         if (track_was_active)
  38.             TrackDeactivate(track_handle);
  39.         tr = _Track_lock(track_handle, &state);
  40.         SetHandleSize(TR.hText, length);
  41.         BlockMove(text, *TR.hText, length);
  42.         TR.selStart = TR.selEnd = length;
  43.         TR.textLength = length;
  44.         TR.topPixel = 0;
  45.         TR.leftPixel = 0;
  46.         _Track_rebuild(track_handle, 0L);
  47.         _Track_unlock(&state);
  48.         if (track_was_active)
  49.             TrackActivate(track_handle);
  50. }
  51.  
  52.